using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using IReaper.Properties;
using IReaper.Command;
using IReaper.RSS;
using System.Collections;
using NewsComponents.Feed;
using NewsComponents.Collections;

namespace IReaper
{
    class FileMonitor
    {
        public static void CheckRootPath(object sender, System.Configuration.SettingChangingEventArgs e)
        {
            if (e.SettingName == "RootPath")
            {
                if (e.NewValue.ToString() == Settings.Default.RootPath)
                    return;
                CommandBase command = CommandManager.GetCommand(CommandFamily.Command_CloseSystem);
                command.Execute(null, null);
                Application.Restart();
            }
        }

        public static void CheckRSSExpire(object sender, System.Configuration.SettingChangingEventArgs e)
        {
            if (e.SettingName == "RemoveItemsOlderThan")
            {
                int days;
                int.TryParse(e.NewValue.ToString(), out days);
                if (days > 0)
                {
                    RSSManager.FeedsHandler.MaxItemAge = new TimeSpan(days, 0, 0, 0);
                    foreach (FeedEntry f in RSSManager.FeedsHandler.FeedsTable)
                    {
                        f.Value.maxitemage = "P" + days.ToString() + "D";
                    }                    
                    RSSManager.SaveFeedList();
                }
            }
        }
    }
}
